package com.zero.guava.samples.CollectionsDemo;

import com.google.common.collect.ComparisonChain;

public class Person implements Comparable<Person> {

    private String name;
    private Integer age;


    Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }


    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     *  使用Guava提供的ComparisonChain进行对象的链式比较
     * @param person
     * @return
     */
    @Override
    public int compareTo(Person person) {
        return ComparisonChain.start()
                .compare(this.name,person.getName())
                .compare(this.age,person.getAge()).result();
    }
}
